package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学生课表 前端控制器
 * </p>
 *
 * @author Ys
 * @since 2023-08-06
 */
@Api(tags = "我的课表")
@RestController
@RequestMapping("/learning-lesson")
public class LearningLessonController {

    @Autowired
    public ILearningLessonService learningLessonService;

    @ApiOperation("分页查询我的课表")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> findByPage(PageQuery pageQuery){
        return learningLessonService.findByPage(pageQuery);
    }

    @ApiOperation("查询最近学习的一个课程")
    @GetMapping("/now")
    public LearningLessonVO findNowLesson(){
        return learningLessonService.findNowLesson();
    }

    @GetMapping("/{courseId}")
    @ApiOperation("查询指定ID的课程学习状态")
    public LearningLessonVO findLessonStatus(@PathVariable("courseId") Long courseId){
        return learningLessonService.findLessonStatus(courseId);
    }

    @GetMapping("/{courseId}/valid")
    @ApiOperation("校验当前用户是否可以播放当前视频")
    public Long validLesson(@PathVariable("courseId") Long courseId){
        return learningLessonService.validLesson(courseId);
    }

    @GetMapping("/lessons/{courseId}/count")
    @ApiOperation("系统指定课程学习人数")
    public Integer countLesson(@PathVariable("courseId") Long courseId) {
        return learningLessonService.countLesson(courseId);
    }

    @PostMapping("/plans")
    @ApiOperation("创建学习计划")
    public void createLearningPlans(@Valid @RequestBody LearningPlanDTO planDTO){
        learningLessonService.createLearningPlan(planDTO);
    }

    @GetMapping("/plans")
    @ApiOperation("查询学习计划")
    public LearningPlanPageVO findLearningPlans(PageQuery pageQuery){
        return learningLessonService.findLearningPlans(pageQuery);
    }

}
